package com.etc.zmall.dao.impl;

import com.etc.util.DBUtil;
import com.etc.util.PageData;
import com.etc.zmall.dao.ShopCarDao;
import com.etc.zmall.entity.Shopc;
/**
 * 购物车dao实现类
 * @author
 *
 */
public class ShopCarDaoImpl implements ShopCarDao {
	/**
	 * 查询用户自己的全部购物车
	 */
	@Override
	public PageData<Shopc> selShopCar(int userid, int page, int pageSize, String keywords) {
		String sql = "select * from tbl_shopc where userid=? and goodsname like ?";
		PageData<Shopc> pd = DBUtil.exQueryByPage(sql, Shopc.class, page, pageSize, userid,"%" + keywords + "%");
		return pd;
	}
	/**
	 * 将商品加进购物车
	 */
	@Override
	public boolean addShopCar(Shopc shopc) {
		String sql = "insert into tbl_shopc values(null,?,?,?,?,?)";
		return DBUtil.exUpdate(sql, shopc.getUserid(), shopc.getShopid(), shopc.getGoodsname(), shopc.getShopccount(),
				shopc.getTotal());

	}
	/**
	 * 删除购物车商品
	 */
	@Override
	public boolean delShopCar(int userid, String goodsname) {
		String sql = "delete from tbl_shopc where userid=? and goodsname=?";
		return  DBUtil.exUpdate(sql, userid, goodsname);
	}

}
